package com.qf.service.impl;

import com.qf.dao.CommunityMapper;
import com.qf.dao.EquipmentMapper;
import com.qf.dao.OwnerMapper;
import com.qf.dao.RepairMapper;
import com.qf.pojo.*;
import com.qf.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RepairServiceImpl implements RepairService {

    @Autowired
    private RepairMapper repairMapper;

    @Autowired
    private CommunityMapper communityMapper;

    @Autowired
    private OwnerMapper ownerMapper;

    @Autowired
    private EquipmentMapper equipmentMapper;

    @Override
    public List<Repair> findByRepairPage() {
        RepairExample repairExample = new RepairExample();
        RepairExample.Criteria criteria = repairExample.createCriteria();
        criteria.andCommunityIdBetween(0,8);

        return repairMapper.selectByExample(null);
    }



    // 添加或修改
    @Override
    public void saveOrUpdateRepair(Repair repair) {
        if (repair.getId() == null) {
            // 新增
            repairMapper.insert(repair);
        } else {
//            System.out.println("此处调用Service下的修改方法");
            repairMapper.updateByPrimaryKey(repair);
        }
    }

    // 根据id查询
    @Override
    public Repair findByRepairId(Integer id) {
        return repairMapper.selectByPrimaryKey(id);
    }

    // 删除
    @Override
    public Integer deleteRepair(Integer id) {
        return repairMapper.deleteByPrimaryKey(id);
    }



    @Override
    public void deleteByRepairId(Integer[] ids) {
        repairMapper.deleteByRepairId(ids);
    }



    @Override
    public List<Community> findAllCommunity() {

        return communityMapper.selectByExample(null);
    }

    @Override
    public List<Owner> findAllOwner() {
        return ownerMapper.selectByExample(null);
    }

    @Override
    public List<Equipment> findAllEquipment() {
        return equipmentMapper.selectByExample(null);
    }

}
